from django.db import models

# Create your models here.
class User(models.Model):
    ON = 1
    OFF = 2
    STATUS_CHOICES ={
        (ON,'正常'),
        (OFF,'锁定')
    }
    class Meta:
        verbose_name_plural = '用户列表'
    user_name=models.CharField(max_length=30,unique=True,verbose_name="用户名")
    pwd=models.CharField(max_length=200,verbose_name="密码")
    status=models.IntegerField(verbose_name="状态",choices=STATUS_CHOICES)
    phone=models.CharField(max_length=30,unique=True,verbose_name="手机号")

class Address(models.Model):
    class Meta:
        verbose_name_plural = '收货地址'
    user=models.ForeignKey("User",on_delete=models.CASCADE,verbose_name="名字")
    user_name=models.CharField(max_length=20,verbose_name="用户名")
    phone=models.CharField(max_length=30,unique=True,verbose_name="手机号")
    address=models.CharField(max_length=200,null=False,verbose_name="收货地址")
    is_default=models.IntegerField(verbose_name="默认值")

class Goods(models.Model):
    k = "克"
    j = "斤"
    g = "个"
    UNIT_CHOICES = {
       (k,"克"),
       (j,"斤"),
       (g,"个")
    }
    class Meta:
        verbose_name_plural = '商品列表'
    good_name=models.CharField(max_length=30,verbose_name="商品名称")
    img_url=models.ImageField(upload_to='ing',verbose_name="商品图片")
    price=models.IntegerField(verbose_name="商品价格")
    intro=models.TextField(verbose_name="商品介绍")
    type=models.ManyToManyField("Type",null=True,verbose_name="商品类型")

    unit=models.CharField(choices=UNIT_CHOICES,default="克",max_length=10,verbose_name="商品单位")
    #    unit=models.CharField(max_length=30,verbose_name="商品单位",choices=UNIT_CHOICES)
    objects = models.Manager()

    def __str__(self):
        return self.good_name


class Type(models.Model):
    class Meta:
        verbose_name_plural = '商品分类'
    type_name=models.CharField(max_length=30,unique=True,verbose_name="类型")

class Cart(models.Model):
    class Meta:
        verbose_name_plural = '购物车'
    num=models.IntegerField()
    user=models.ForeignKey("User",on_delete=models.CASCADE)
    goods=models.ManyToManyField(Goods)

class Order(models.Model):
    class Meta:
        verbose_name_plural = '订单列表'
    order_on=models.CharField(max_length=30,unique=True)
    statue=models.IntegerField(verbose_name="状态")
    time=models.DateTimeField(auto_now_add=True,verbose_name="时间")
    user_name=models.CharField(max_length=20,verbose_name="用户名")
    phone=models.CharField(max_length=30,verbose_name="手机号")
    address=models.CharField(max_length=200,verbose_name="收货地址")
    user=models.ForeignKey("User",on_delete=models.CASCADE,verbose_name="名字")
    total_price=models.IntegerField(verbose_name="总价")
    pay_status=models.IntegerField(verbose_name="支付状态")

class OrderDetail(models.Model):
    class Meta:
        verbose_name_plural = '订单详情表'
    good_name=models.CharField(max_length=30,verbose_name="商品名称")
    price=models.IntegerField(verbose_name="数量")
    num=models.IntegerField()
    img_url=models.CharField(max_length=100,verbose_name="商品图片")
    total_price=models.IntegerField(verbose_name="总价")
    order=models.ForeignKey("Order",on_delete=models.CASCADE)